#include <stdio.h>

int is_palindrome(unsigned long a){
	char s[12]; int n,i;
	sprintf(s,"%lu",a);
	n=strlen(s);
	for(i=0;i<n/2;i++)	if(s[i]!=s[n-1-i])	return 0;
	return 1;
	
}

unsigned long reverse(unsigned long a){
	char s[12],res[12];int n,i;
	sprintf(s,"%lu",a);
	n=strlen(s);
	for(i=0;i<n;i++)	res[i]=s[n-1-i];
	res[n]=0;
	sscanf(res,"%lu",&a);
	return a;
}

int reverse_add(long unsigned *a){
	unsigned long n=*a;int count=0;
	while(!is_palindrome(*a)){
		*a+=reverse(*a);
		count++;
	}
	return count;
}

int main(){
	long unsigned a;
	int N;
	int count;
	
	scanf("%d",&N);
	while(N--)
	{
		scanf("%lu",&a);
		printf("%d %lu\n",reverse_add(&a), a);
	}
	
	return 0;
}
